package org.jg.arkanoid.controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class KeyBoardListener implements KeyListener{

	private static Logger LOG = LogManager.getLogger("KeyBoardListener.class");
	
	Collection<KeyListener> keyListeners = new ArrayList<KeyListener>();
	
    public void addKeyListener(KeyListener keyListener)
    {
    	keyListeners.add(keyListener);
    }
	
	@Override
	public void keyPressed(KeyEvent e) {
		LOG.info(e.getKeyCode() + " pressed");
		for(KeyListener listener: keyListeners)
		{
			listener.keyPressed(e);
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		LOG.info(e.getKeyCode() + " released");
		for(KeyListener listener: keyListeners)
		{
			listener.keyReleased(e);
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
		LOG.info(e.getKeyCode() + " typed");
		for(KeyListener listener: keyListeners)
		{
			listener.keyTyped(e);
		}
	}

}
